package com.ruoyi.system.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysFlyingBook;
import com.ruoyi.system.service.ISysFlyingBookService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 飞书配置Controller
 *
 * @author ruoyi
 * @date 2024-11-30
 */
@RestController
@RequestMapping("/system/flying_book")
public class SysFlyingBookController extends BaseController
{
    @Autowired
    private ISysFlyingBookService sysFlyingBookService;

    /**
     * 查询飞书配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:flying_book:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysFlyingBook sysFlyingBook)
    {
        startPage();
        List<SysFlyingBook> list = sysFlyingBookService.selectSysFlyingBookList(sysFlyingBook);
        return getDataTable(list);
    }

    /**
     * 导出飞书配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:flying_book:export')")
    @Log(title = "飞书配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysFlyingBook sysFlyingBook)
    {
        List<SysFlyingBook> list = sysFlyingBookService.selectSysFlyingBookList(sysFlyingBook);
        ExcelUtil<SysFlyingBook> util = new ExcelUtil<SysFlyingBook>(SysFlyingBook.class);
        util.exportExcel(response, list, "飞书配置数据");
    }

    /**
     * 获取飞书配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:flying_book:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysFlyingBookService.getById(id));
    }

    /**
     * 新增飞书配置
     */
    @PreAuthorize("@ss.hasPermi('system:flying_book:add')")
    @Log(title = "飞书配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysFlyingBook sysFlyingBook) {
        return toAjax(sysFlyingBookService.save(sysFlyingBook));
    }

    /**
     * 修改飞书配置
     */
    @PreAuthorize("@ss.hasPermi('system:flying_book:edit')")
    @Log(title = "飞书配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysFlyingBook sysFlyingBook) {
        return toAjax(sysFlyingBookService.updateById(sysFlyingBook));
    }

    /**
     * 删除飞书配置
     */
    @PreAuthorize("@ss.hasPermi('system:flying_book:remove')")
    @Log(title = "飞书配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysFlyingBookService.removeByIds(Arrays.asList(ids)));
    }
}
